import axios from 'axios';
import { message } from 'antd';
export const Require =(options)=>{
	return new Promise ((resolve,reject)=>{

		const params={
			method: options.method || 'get',
        	url:options.url||'',
        	withCredentials: true,
		}
		switch(params.method.toUpperCase())
		{
			case "GET":
			case "DELETE":
				params.params = options.data;
				break;
			default:
				params.data =  options.data;
		}
		axios(params)
		 .then(result=>{
		 	let data = result.data;
		 	if(data.code == 10){
		 		window.location.href = '/login';
		 		reject()
		 	}
		 	else{
		 		resolve()
		 	}
		 })
		 .catch(err=>{
		 	console.log(err);
        	// message.error('网络错误123，请稍后重试');
		 })
	})
}

